﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AuthorityRoleMenuRelaEdit.aspx.cs" Inherits="_2010web.Manage.authority.AuthorityRoleMenuRelaEdit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
     <!-- #include file="~/html/file.aspx" -->
    <style>
        .checkbox_grp {
            padding-left: 12px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div class="alert_info alert_callc" style="min-height: 480px;">
            <div class="main_blc">

                <div class="limits_edit" id="selectList">
                    <%=strHtml %>
                    <div class="btns">
                        <a href="javascript:void(0);" class="submit">
                            <input type="button" onclick="Save()" value="确定">
                        </a><a href="javascript:void(0);" onclick="return false;" class="cancel">
                            <input type="button" value="取消" onclick="parent._M.CallBack('_M.CloseIframe()');">
                        </a>
                    </div>
                </div>

            </div>
        </div>


        <script language="javascript">
            function Save() {
                var $checkedlist = "";
                var $selectList = $("#selectList");
                $selectList.find(".ckb").each(function () {
                    var $this = $(this);
                    if ($this.prop("checked") == true) {
                        if ($checkedlist == "") {
                            $checkedlist += $this.val();
                        } else {
                            $checkedlist +=","+ $this.val();
                        }
                    }

                });
                var $data = "ty=saverolemenurela&roleid=<%=intRoleID%>&menuid=" + $checkedlist + "&sysid=<%=intSystemID%>";
                $.ajax({
                    type: "POST",
                    url: "../ajax/ajaxauthrole.aspx",
                    timeout: 20000,
                    data: $data,
                    beforeSend: function (XMLHttpRequest) {
                        //数据处理中

                    },
                    success: function (data, textStatus) {
                        //请求成功
                        $().AjaxManage.MessageOpen("权限设置成功");
                        setTimeout("top.window.location.href = top.window.location.href", 500);

                    },
                    complete: function (XMLHttpRequest, textStatus) {
                        //HideLoading();
                    },
                    error: function () {
                        //请求出错处理
                    }
                });
            }
            $("#selectList").find(".ckb").bind("click", function () {
                var $this = $(this);
                var $thisCheck = false;
                if($this.attr("checked")==null)
                {
                    $(this).attr("checked", true);
                    $thisCheck = true;
                }else
                {
                    $(this).removeAttr("checked");
                }
                var $thisVal = $this.val();
                var $Level = $this.attr("level");
                var $checkselect = true;
                //点击一级菜单
                if ($Level == 1) {
                    //改变全部二级菜单
                    $this.parents("dl").find("dd").find("input").each(function () {
                        $(this).prop("checked", $thisCheck);
                    });
                }
                //点击二级菜单
                if ($Level == 2) {
                    //如果是选中，那么一级菜单也是选中状态
                    if ($thisCheck == true) {
                        $this.parents("dl").find("dt").find("input").each(function () {
                            $(this).prop("checked", $thisCheck);
                        });
                    } else {
                        //如果是取消选中，判断二级菜单中是否有选中状态的，如果没有就取消一级菜单的选中状态
                        $this.parents("dd").find("input").each(function () {
                            if ($(this).attr("checked") !=null) {
                                $checkselect = false;
                            }
                        });
                        if ($checkselect == true) {
                            $this.parents("dl").find("dt").find("input").each(function () {
                               $(this).removeAttr("checked");
                            });
                        }
                    }
                }
         

            });
            <%=strMessage %>
        </script>
    </form>
</body>
</html>
